const fs = require('fs')
const path = require('path')

const regStyle = /<style>[\s\S]*<\/style>/
const regScript = /<script>[\s\S]*<\/script>/

fs.readFile(path.join(__dirname,'index.html'),'utf8',function(err,data){
    if(err){
        return console.log('失败')
    }
    resolveCSS(data)
    resolveJS(data)

})
// 定义处理css样式
function resolveCSS(data){
    const r1 = regStyle.exec(data)
    const newCSS = r1[0].replace('<style>','').replace('</style>','')

    fs.writeFile(path.join(__dirname,'index.css'),newCSS,function(err){
        if(err){
            return console.log('失败') 
        }
        console.log('css成功')
    })
}
// 定义处理js
function resolveJS(data){
    const r1 = regScript.exec(data)
    const newJs = r1[0].replace('<script>','').replace('</script>','')

    fs.writeFile(path.join(__dirname,'index.js'),newJs,function(err){
        if(err){
            return console.log('失败')
        }
        console.log('js成功')
    })
}

